package ywpt.model;

import java.text.DecimalFormat;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.util.StrutsTypeConverter;

public class BooleanConverter extends StrutsTypeConverter {
	@SuppressWarnings("unused")
	private static final Log	_log	= LogFactory.getLog(BooleanConverter.class);

	@SuppressWarnings("unchecked")
	@Override
	public Object convertFromString(Map context, String[] values, Class toClass) {
		if (values.length > 0 && values[0] != null && values[0].trim().length() > 0) {
			return Double.parseDouble((values[0]));
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String convertToString(Map context, Object o) {
		if (o instanceof Double) {
			DecimalFormat fmt = new DecimalFormat("##0.00");
			return fmt.format((Double) o);
		}
		return "";
	}
}
